package com.nccsjz.back.resources.service;
import java.sql.SQLException;
import java.util.List;

import com.nccsjz.base.BaseService;
import com.nccsjz.back.resources.dao.ResourcesDAO;
import com.nccsjz.pojo.Resources;
import com.nccsjz.utils.Pager;
public class ResourcesService extends BaseService{
     //add resources
	public boolean addResources(Resources res) throws SQLException{
		boolean flag=false;
		try{
			openCon();
			flag=new ResourcesDAO(con).addResources(res);
		}finally{
			closeCon();
		}
		return flag;
	}
	//delete resources
	public boolean deleteResources(Long id) throws SQLException{
		boolean flag=false;
		try{
			openCon();
			flag=new ResourcesDAO(con).deleteResources(id);
		}finally{
			closeCon();
		}
		return flag;
	}
	//delete batch resources
	public boolean deleteBatchResouces(List<Long> list) throws SQLException{
		boolean flag=false;
		try{
			openCon();
			con.setAutoCommit(false);
			flag=new ResourcesDAO(con).deleteBatchResources(list);
			con.commit();
		}finally{
			closeCon();
		}
		return flag;
	}
	//page dispaly resources
	public Pager getResources(int pageSize,int pageNo) throws SQLException{
		Pager pager=null;
		try{
			openCon();
			pager=new ResourcesDAO(con).getResources(pageSize, pageNo);
		}finally{
			closeCon();
		}
		return pager;
	}
	//get one Resource
	public Resources getResources(Long id) throws SQLException{
		Resources res=null;
		try{
			openCon();
			res=new ResourcesDAO(con).getReources(id);
		}finally{
			closeCon();
		}
		return res;
	}
	//select resource by title
	public Pager getResources(int pageSize,int pageNo,String title) throws SQLException{
		Pager pager=null;
		try{
			openCon();
			pager=new ResourcesDAO(con).getResources(pageSize, pageNo,title);
		}finally{
			closeCon();
		}
		return pager;
	}
}
